<?php
class Renew_Model_BukkenCampaign extends Apm_Model_Base {
	public function getHeyaCampaigns($code) {
		$sql = "
			select
				b.M94_CAMPAIGN_CD,
				b.M94_CAMPAIGN_URL,
				b.M94_CAMPAIGN_NAME,
				c.M94_ITEM_ICON,
				c.M94_ITEM_BANNER
			from
			        T03WEB_HEYA_CAMPAIGN a
			        ,M94CAMPAIGN         b
			        ,M94CAMPAIGN_ITEM    c
			WHERE a.T03_HEYA_CD = ".$code."
			AND b.M94_CAMPAIGN_CD = a.T03_CAMPAIGN_CD
			AND NVL(b.M94_START_YMD,'99999999') <= TO_CHAR(SYSDATE, 'YYYYMMDD')
			AND NVL(b.M94_END_YMD,'99999999')   >= TO_CHAR(SYSDATE, 'YYYYMMDD')
			AND b.M94_DELETE_FLAG = 0
			AND b.M94_MOBILE_KBN  = '0'
			AND c.M94_CAMPAIGN_CD = a.T03_CAMPAIGN_CD
			AND (c.M94_ITEM_CD     = a.T03_OTAKARA_CD or c.M94_CAMPAIGN_CD = 11)
			AND NVL(c.M94_INSERT_DATE, SYSDATE+1) <= SYSDATE
			AND c.M94_DELETE_FLAG = 0
			AND (c.M94_DELETE_DATE > SYSDATE or c.M94_DELETE_DATE is null)
			group by 
				b.M94_CAMPAIGN_CD,
				b.M94_CAMPAIGN_URL,
				b.M94_CAMPAIGN_NAME,
				c.M94_ITEM_ICON,
				c.M94_ITEM_BANNER,
				b.M94_CAMPAIGN_TOKUSYU_KBN,
				b.M94_CAMPAIGN_PRIORITY_NO,
				b.M94_START_YMD
			order by b.M94_CAMPAIGN_TOKUSYU_KBN, b.M94_CAMPAIGN_PRIORITY_NO, b.M94_START_YMD desc";
		return $this->dbGetList($sql);
	}

	public function getNormalCampaigns() {
		$sql = "
			SELECT
				b.M94_CAMPAIGN_CD,
				b.M94_CAMPAIGN_URL,
				b.M94_CAMPAIGN_NAME,
				c.M94_ITEM_ICON,
				c.M94_ITEM_BANNER
			FROM 
				M94CAMPAIGN b
					LEFT OUTER JOIN M94CAMPAIGN_ITEM c
						ON c.M94_CAMPAIGN_CD = b.M94_CAMPAIGN_CD
						AND c.M94_ITEM_CD = 1
						AND NVL(c.M94_INSERT_DATE, SYSDATE+1) <= SYSDATE
						AND c.M94_DELETE_FLAG = 0
						AND (c.M94_DELETE_DATE > SYSDATE or c.M94_DELETE_DATE is null)
			WHERE 
				b.M94_CAMPAIGN_HYOUZI = 1 
			AND b.M94_DELETE_FLAG = 0 
			AND b.M94_CAMPAIGN_KBN IN (2,4) 
			AND b.M94_MOBILE_KBN = 0 
			AND NVL(b.M94_START_YMD,'99999999') <= TO_CHAR(SYSDATE, 'YYYYMMDD')
			AND NVL(b.M94_END_YMD,'99999999')   >= TO_CHAR(SYSDATE, 'YYYYMMDD')
			order by b.M94_CAMPAIGN_TOKUSYU_KBN, b.M94_CAMPAIGN_PRIORITY_NO, NVL(b.M94_START_YMD,'99999999') desc";
		return $this->dbGetList($sql);
	}
}
